<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<!--[if lte IE 6]></base><![endif]-->
		<title>广东科学技术职业学院考生报到系统 >>>>宣保处</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link href="css/newindex.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="css/jquery-ui-1.8.5.custom.css"
			type="text/css" />
		<link href="css/pagecss.css" rel="stylesheet" type="text/css" />
		<script src="js/jquery-1.5.js" language="javascript">
</script>
		<script src="js/table.js" language="javascript">
</script>
		<script src="js/newpublic.js" language="javascript">
</script>
		<script src="js/pageInfo.js" type="text/javascript">
</script>
		<script src="js/jquery-ui-1.8.5.custom.min.js" language="javascript">
</script>


		<script language="javascript">
$(function() {

	$("#content").draggable( {
		cancel : ".contable"
	});
})
$(function(){
		
			var isSpecialUser=${sessionScope.isSpecialUser};//特殊帐号，屏蔽增删改的功能

			if(isSpecialUser){
				window.f1=function(){
					alert("Sorry!!该帐号权限不够，不能进行此操作")
				}
			}
})
var result = null;//查询结果
var initIndex=<s:property value="pageInfo.pageIndex"/>;
var initSize=<s:property value="pageInfo.pageSize"/>;
var index=initIndex;
var size =initSize;
var queryFlag=true;//用于标识进行的操作是查询学生还是查询历史记录
var flag,pageIndex,pageSize;
$(function() {
	flag=1;
	$("input[name='radio'][value=1]").attr("checked",true);  
	//重置，清空输入内容
	$("#reset1").unbind("click").click(function() {
		$("#examCode_input").val("");
		$("#studentName_input").val("");
		$("#idCode_input").val("");
	})

	//查询学生信息
	$("#search").unbind("click").click(function() {
		queryFlag=true;
		ajaxSubmit(initIndex, initSize);
	})
	
	//查询历史记录(默认状态)	
	$("#history").unbind("click").click(function(){$("#area").val("全部");query();})
	
	//查询历史记录(有地区选择)
	$("#areaSearch").unbind("click").click(function(){query();})

	//导出Excel
	$("#export").unbind("click").click(function(){exportHistoryExcel();})
})
	function query(){
		queryFlag=false;
		showProgressBar(true);//显示进度圈
		$("#infoStudent").hide();//隐藏查询记录
		$("#infoHistory").hide();//隐藏历史记录
		$("#queryResult").html("");//将span的内容设为空
		var area=$("#area").val();
		ajaxSubmit(initIndex, initSize);
		
	}

	//根据页面大小、页数，显示历史记录
	function ajaxSubmit(index, size){
		pageIndex = index;
		pageSize = size;
		if(queryFlag){
				var examCode = $("#examCode_input").val();
				var studentName = $("#studentName_input").val();
				var idCode = $("#idCode_input").val();
		
				if (examCode == "" && studentName == "" && idCode == "") {
					//没有输入查询内容
					alert("请输入查询条件")
				} else if (examCode != "" && examCode.length < 5) {
					alert("准考证不能少了5位")
				} else if (idCode != "" && idCode.length < 6) {
					alert("身份证不能少了6位")
				} else {
					showProgressBar(true);//显示进度圈
					$("#infoStudent").hide();//隐藏查询记录
					$("#infoHistory").hide();//隐藏历史记录
					$("#queryResult").html("");//将span的内容设为空
					$.post("json/declareAction!queryStudentInfoToDeclare",{"pageInfo.pageIndex":index,"pageInfo.pageSize":size,"examCode" : examCode,"studentName" : studentName,
							"idCode":idCode,"date" : new Date()},function(data) {
								showResult(data)
								showPage($("#infoStudent"));
								var page=eval("("+data.pageJson+")")
								initPage(page.totalPage, page.pageIndex, page.pageSize, page.totalRec);	
								showProgressBar(false) //隐藏进度圈
					})
				}
		}else{
			
			$.post("json/declareAction!historyOfRemoveByArea",{"pageInfo.pageIndex":index,"pageInfo.pageSize":size,"date":new Date(),'area':$("#area").val()},function(data) {
					showResultOfHistory(data)
					showPage($("#HistoryData"));
					var page=eval("("+data.pageJson+")")
					showProgressBar(false) //隐藏进度圈
					initPage(page.totalPage, page.pageIndex, page.pageSize, page.totalRec);	
			})
		}
	}
	
	//显示查询结果
	function showResult(data) {
		result = eval("(" + data.declareResult_json + ")");
		//alert(result.length);
		if (result.length <= 0){		
			$("#queryResult")
					.html(
							"<font style='text-align:center;font-size:16px;color:red;'>没有查到符合条件的同学!</font>");
		}
		else {		
			clearMessage();
			for ( var i = 0; i < result.length; i++) {
				fillContent(result[i],i+1)
			}
		}
	}
	
	//显示历史记录
	function showResultOfHistory(data) {
		result = eval("(" + data.declareHistory_json + ")");
		//alert(result.length);
		if (result.length <= 0){
			
			$("#queryResult")
					.html(
							"<font style='text-align:center;font-size:16px;color:red;'>尚未有迁入记录!</font>");
		}
		else {		
			clearMessage();		
			var page = eval('(' + data.pageJson + ')');
			//alert(page)
			initPage(page.totalPage, page.pageIndex, page.pageSize, page.totalRec);	
			
			for ( var i = 0; i < result.length; i++) {
				fillContentOfHistory(result[i],i+1)
			}
		}
	}
	
	//清除数据
	function clearMessage() {
		$("tr[name='showStudentMessage']").remove();
		$("tr[name='showHistoryMessage']").remove();
	}
	//填充查询信息内容
	function fillContent(stu,num) {
	
		$("#infoStudent").show();
		var number = num; 
		var studentId = stu.studentId;
		var name = stu.studentName;
		var examCode = stu.examCode;
		var idCode = stu.idCode;
		var sex = (stu.sex == true ? '男' : '女');
		var area = stu.area;
		var remove = (stu.remove == true ? '<font color="#FF0000">已迁入</font>' : '未迁入');
	
		//alert(stu.studentId);
		var tr;	
		if(num%2==0){
			tr = '<tr style="background-color:#deefff" name="showStudentMessage">';
		} else {
			tr = '<tr style="background-color:#ffffff" name="showStudentMessage">';
		}	
	    tr+=  '<td id="number" height="20" align="center">' + number
			+ '</td><td id="stuName" height="20" align="center">' + name
			+ '</td><td id="stuExamCode" height="20" align="center">' + examCode 
			+ '</td><td id="idCode" height="20" align="center">' + idCode
			+ '</td><td id="sex" height="20" align="center">' + sex
			+ '</td><td id="area'+num+'"height="20" align="center">' + area
			+ '</td><td id="operation" height="20" align="center">' +
			  (stu.remove==true?
				 '<input type="button" value="户口迁入" onclick="f1('+studentId+','+num+')" id="bu1'+num+'" disabled="true" />&nbsp;'
				 + '<input type="button" value="撤消" onclick="f2('+studentId+','+num+')" id="bu2'+num+'"/>'
			  :
				 '<input type="button" value="户口迁入" onclick="f1('+studentId+','+num+')" id="bu1'+num+'"/>&nbsp;'
				 + '<input type="button" value="撤消" onclick="f2('+studentId+','+num+')" id="bu2'+num+'" disabled="true" />'
			  )
			+ '</td><td id="remove" height="20" align="center"><div id="t2'+num+'">' + remove
			+ '</div></td></tr>';
	
		$("#showStudentTable").append($(tr)); 
	}
	//填充历史记录内容
	function fillContentOfHistory(his,num) {
	
		$("#infoHistory").show();
		var number = num; 		
		var studentName = his.studentName;
		var examCode = his.examCode;
		var idCode = his.idCode;
		var sex = (his.sex == true ? '男' : '女');
		var operateTime = his.operateTime;
		var operateDescription = his.operateDescription;
		
		var tr;	
		if(num%2==0){
			tr = '<tr style="background-color:#deefff" name="showHistoryMessage">';
		} else {
			tr = '<tr style="background-color:#ffffff" name="showHistoryMessage">';
		}	
	    tr+=  '<td id="number" height="20" align="center">' + number
			+ '</td><td id="stuName" height="20" align="center">' + studentName
			+ '</td><td id="stuExamCode" height="20" align="center">' + examCode 
			+ '</td><td id="idCode" height="20" align="center">' + idCode
			+ '</td><td id="sex" height="20" align="center">' + sex
			+ '</td><td id="operateTime" height="20" align="center">' + operateTime
			+ '</td><td id="operateDescription" height="20" align="center">' + operateDescription
			+ '</td></tr>';		 
		$("#showHistoryTable").append($(tr));
	}
	//显示进度圈，当isShow为false时不显示,true则显示
	function showProgressBar(isShow) {
		if (isShow) {
			$("#progressBar").show();
		} else {
			$("#progressBar").hide();
		}
	}
			
	function f1(studentId,num) {
		if (confirm("是否迁入？")) {
		
			$.post("json/declareAction!removeIn",{'studentId' : studentId,"date" : new Date()},function(data) {
				resultOfRemove = eval("(" + data.declareRemove_json + ")");
				//alert(resultOfRemove);
				if(resultOfRemove==true){
					alert("户口迁入成功");
					document.getElementById("bu1"+num).disabled = true;
					document.getElementById("bu2"+num).disabled = false;
					document.getElementById("t2"+num).innerHTML = "<font color='#FF0000'>已迁入</font>";
					document.getElementById("area"+num).innerHTML = "广州市";
				}else
					alert("户口迁入失败");
			})
		}
	}
	function f2(studentId,num) {
		if (confirm("是否撤销？")) {
		
		$.post("json/declareAction!removeBack",{'studentId' : studentId,"date" : new Date()},function(data) {
				var resultOfRemove = eval("(" + data.declareRemove_json + ")");
				var areaName = eval("(" + data.areaJson + ")");
				//alert(resultOfRemove);
				if(resultOfRemove==true){
					alert("撤销迁入成功");
					document.getElementById("bu1"+num).disabled = false;
					document.getElementById("bu2"+num).disabled = true;
					document.getElementById("t2"+num).innerHTML = "未迁入";
					document.getElementById("area"+num).innerHTML = areaName.toString();
				}else
					alert("撤销迁入失败");
			})
		}
	}
	var preParent;
	function showPage(parent){
		var pageTable=$("table#pageTable").clone();
		$("table#pageTable").remove();
		if(preParent){
			preParent.find("table#pageTable").remove();
		}
		parent.append(pageTable);
		preParent=$("#infoStudent")

	}
	function setFlag(s){
		flag = s;
	}
	function exportHistoryExcel() {
		var url = 'exportHistoryExcel.action?flag=' +flag;
		if(flag==1){
			url += '&index='+pageIndex+'&pageSize='+pageSize;
		}
		
		$("#export_excel_form").attr("action",url).submit();
	}
	
</script>

	</head>

	<body onload="fixPNGAll()">
		<div id="bg">
			<div id="bodydiv">
				<div id="bodytitle">
					宣保处
					<div>
						<a href="logoutAction" style="color: #F00;">退出</a>
					</div>
				</div>
				<div id="content">
					<!--当前位置CSS-->
					<div class="top">
						<div class="topleft">
							<div class="dan">
								<div>
									当前位置>宣保处
								</div>
							</div>
							<div class="F5">
								<img src="newimages/F5.png" />
							</div>
						</div>
						<div class="topright">
							<div class="toprightmin"></div>
							<div class="toprightmax"></div>
							<div class="toprightclose"
								onclick="if(confirm('是否确定退出！')){location.replace('loginoutAction')}"
								title="点击退出"></div>
						</div>
					</div>
					<!---->
					<!--内容-->
					<div class="condiv">
						<div class="submenu">

						</div>
						<div class="contable">
							<div class="title">
								户口迁移查询
							</div>
							<!--****************************************-->
							<table width="382" border="0" align="center" cellpadding="0"
								cellspacing="5">
								<tr>

									<td width="90" align="right">

										姓名：
									</td>
									<td width="137">
										<input type="text" size="15" id="studentName_input" />
									</td>
									<td width="129" rowspan="4"
										style="border-left: 1px red dotted;">
										<input type="button" value="查看迁移历史记录" id="history" />
										<!--onclick="document.getElementById('t1').style.display='none'; document.getElementById('date').style.display='block';" -->
									</td>
								</tr>
								<tr>
									<td align="right" width="150">
										准考证：
									</td>
									<td align="center">
										<input type="text" size="15" id="examCode_input" />
									</td>
								</tr>
								<tr>
									<td align="right" width="150">
										身份证：
									</td>
									<td align="center">
										<input type="text" size="15" id="idCode_input" />
									</td>
								</tr>
								<tr>
									<td colspan="2" align="center">
										<input type="button" id="search" value="查询" />
										<!--onclick="document.getElementById('t1').style.display='block';document.getElementById('date').style.display='none';" -->

										&nbsp;&nbsp;
										<input type="button" id="reset1" value="重置" />
									</td>
								</tr>
							</table>

							<span style="color: #F00; font-size: 16px;" id="queryResult"></span>
							<div id="progressBar" style="display: none">
								<!-- 进度圈 -->
								<center>
									<img src="images/loading.gif" />
								</center>
							</div>

							<!---->
							<div id="infoStudent" style="display: none;">
								<table width="90%" border="0" align="center" cellpadding="0"
									cellspacing="1"
									style="margin-top: 50px; border: 1px solid #5cb0ff;" class="t1"
									id="showStudentTable">
									<tr>
										<th width="10%" height="27" align="center">
											编号
										</th>
										<th width="10%" align="center">
											姓名
										</th>
										<th width="13%" align="center">
											准考证
										</th>
										<th width="13%" align="center">
											身份证
										</th>
										<th width="10%" align="center">
											性别
										</th>
										<th width="14%" align="center">
											户口所在地
										</th>
										<th width="21%" align="center">
											操作
										</th>
										<th width="9%" align="center">
											状态
										</th>
									</tr>
									<tr name="showStudentMessage">
										<td id="number" height="20" align="center"></td>
										<td id="stuName" align="center"></td>
										<td id="stuExamCode" align="center"></td>
										<td id="idCode" align="center"></td>
										<td id="sex" align="center"></td>
										<td id="area" align="center"></td>
										<td id="operation" align="center">
											<input type="button" onclick="f1()" value="户口迁入" id="bu1" />
											&nbsp;
											<input type="button" value="撤消" id="bu2" onclick="f2()"
												disabled="true" />
										</td>
										<td id="remove" align="center">
											<div id="t2"></div>
										</td>
									</tr>
								</table>
							</div>

							<div id="infoHistory" style="display: none;">
								<div>
									<table width="90%" border="0" align="center" cellpadding="0"
										cellspacing="3">
										<tr>
											<td width="10%" align="left">
												户口所在地：
											</td>
											<td width="90%" rowspan="2">
												<select name="area" id="area">
													<option value="全部" selected="selected">
														全部
													</option>
													<option value="珠海">
														珠海
													</option>
													<option value="广州">
														广州
													</option>
													<option value="汕头">
														汕头
													</option>
													<option value="汕尾">
														汕尾
													</option>
													<option value="潮州">
														潮州
													</option>
													<option value="揭阳">
														揭阳
													</option>
													<option value="河源">
														河源
													</option>
													<option value="惠州">
														惠州
													</option>
													<option value="梅州">
														梅州
													</option>
													<option value="韶关">
														韶关
													</option>
													<option value="湛江">
														湛江
													</option>
													<option value="茂名">
														茂名
													</option>
													<option value="肇庆">
														肇庆
													</option>
													<option value="清远">
														清远
													</option>
													<option value="云浮">
														云浮
													</option>
													<option value="东莞">
														东莞
													</option>
													<option value="江门">
														江门
													</option>
													<option value="阳江">
														阳江
													</option>
													<option value="中山">
														中山
													</option>
													<option value="佛山">
														佛山
													</option>
													<option value="深圳">
														深圳
													</option>
												</select>
												<input type="button" value="确认" id="areaSearch" />
											</td>
											<!--  									
											<td width="22%" align="right">
												<input type="radio" name="radio" id="radio" value="radio"
													checked="checked" />
												本页
											</td>
											<td width="21%" rowspan="2">
												&nbsp;&nbsp;
												<input type="button" value="导出" />
											</td>											
										</tr>
										<tr>
											<td height="26" align="right">
												<input type="radio" name="radio" id="radio" value="radio" />
												全部
											</td>
-->
										</tr>
									</table>
								</div>
								<div id="HistoryData">

									<table width="90%" height="79" border="0" align="center"
										cellpadding="0" cellspacing="1"
										style="border: 1px solid #5cb0ff;" class="t1"
										id="showHistoryTable">
										<tr>
											<th width="7%" align="center">
												编号
											</th>
											<th width="7%" align="center">
												姓名
											</th>
											<th width="17%" align="center">
												准考证
											</th>
											<th width="21%" align="center">
												身份证
											</th>
											<th width="10%" align="center">
												性别
											</th>
											<th width="19%" align="center">
												操作时间
											</th>
											<th width="19%" align="center">
												具体内容
											</th>
										</tr>
										<tr name="showHistoryMessage">
											<td align="center">
												1
											</td>
											<td align="center">
												XXX
											</td>
											<td align="center">
												132
											</td>
											<td align="center">
												123
											</td>
											<td align="center">
												男
											</td>
											<td align="center">
												2001年9月7日 15:30:20
											</td>
											<td align="center">
												从佛山迁入广州
											</td>
										</tr>
									</table>
									<div id="pageDiv" style="display: none">
										<!--上一页，下一页 开始-->
										<table width="90%" class="pagecss" id="pageTable"
											align="center">
											<tr>
												<td align="left">
													<span id="AllPage">共几页/几条</span>
													<span id="setupNum">显示每页记录条数</span>
													<select id="setSize"
														onchange="ajaxChangeCount(this.options[this.options.selectedIndex].value)">
													</select>
												</td>
												<td align="right">
													<span id="Flexigrid_Bar"><a href="">上5页</a><span
														class="dan">1</span><a href="">2</a><a href="">3</a><a
														href="">下5页</a> </span>
													<span id="checkPage"><input type="text"
															style="width: 20px;"> &nbsp;页<a href="">GO</a> </span>
												</td>
											</tr>
										</table>
										<!--上一页，下一页 结束-->

									</div>
								</div>
								<div>
									<form action="" method="post" id="export_excel_form">
										<table width="100%" border="0" cellspacing="5" cellpadding="0">

											<tr>
												<td width="91%" align="right">
													<input type="radio" name="radio" id="radio" value="1"
														onclick="setFlag(1)" checked="checked" />
													本页
												</td>
												<td width="9%" rowspan="2">
													<input type="button" id="export" value="导出" />
												</td>
											</tr>

											<tr>
												<td align="right">
													<input type="radio" name="radio" id="radio" value="2"
														onclick="setFlag(0)" />
													全部
												</td>
											</tr>
										</table>
									</form>
								</div>
							</div>
							<!--****************************************-->
						</div>
					</div>
					<!---->

					<div>

					</div>




					<!---->
					<div class="condiv"
						style="width: 997px; position: relative; height: 20px; min-height: 20px; text-align: center;">
						<a href="computer/computer.html" target="_blank">计算机学院程序员之家</a>
					</div>
					<!---->

					<!--低部-->
					<div class="bottom">
						&nbsp;
					</div>
					<!---->
				</div>
			</div>
		</div>

	</body>
</html>
